function UsedMine(ply,ent) 
	if(ent:GetName()=="button_metal_1") then
		if(!timer.IsTimer(ply:Name().."metal")) then
			local metal= ents.Create("metal")
			metal:SetPos(ents.FindByName("metalspawn_1")[1].Entity:GetPos())
			metal:Spawn()
			ply:ChatNotify("Mined one ore")
			timer.Create(ply:Name().."metal",1,1,function () timer.Destroy(ply:Name().."metal") end)
		end
	end 
end 
hook.Add('PlayerUse',"usedmine", UsedMine)

function UsedGunStore(ply,ent) 
	if(ent:GetName()=="button_gun_1") then 
		if(!timer.IsTimer(ply:Name() .. "gunmaker")) then
		if(ply.inventory.metal==nil) then
				ply.inventory.metal=0
		end

		umsg.Start("buildweapon", ply)
			umsg.Long(ent:EntIndex())			
			umsg.Long(ply.inventory.metal)
		umsg.End()

		timer.Create(ply:Name().."gunmaker",1,1,function()		
			timer.Destroy(ply:Name().."gunmaker")
			end)
		end
 	end 
end 

hook.Add('PlayerUse',"usedgunstore", UsedGunStore)

function UsedWelfare(ply,ent)
	if(ent:GetName()=="welfare_1") then -- whoops this should've been button_welfare_1 o well.
		if(timer.IsTimer(ply:Name().."welfare")) then return end
		if(ply.welfare==nil) then
			ply:ChatNotify("I'm sorry, your welfare account has not been setup. Please wait a few minutes. If the problem persists, see an Administrator")
		elseif(ply.welfare==0) then
			ply:ChatNotify("You have no welfare payments. Come back later")
		else
			ply.inventory.money=ply.inventory.money+ply.welfare
			ply:ChatNotify("You collected "..ply.welfare.." from welfare")
			ply.welfare=0
		end
		timer.Create(ply:Name().."welfare",1,1,function()		
			timer.Destroy(ply:Name().."welfare")
			end)
	end
end


hook.Add('PlayerUse',"usedwelfare", UsedWelfare)

function CreateWeapon(ply,command,arguments)
	local type= arguments[1]
	local cost= GunPrices[type]
	
	if(ply.inventory.metal==nil) then
		return
	end
	if(ply.inventory.metal>=cost) then
			ply.inventory.metal=ply.inventory.metal-cost
			print("Subtracted" .. cost .." metal")
			local gun= ents.Create(type)
			gun:SetPos(ents.FindByName("gunspawn_1")[1].Entity:GetPos())
			gun:Spawn()
			ply:ChatNotify("Weapon: ".. type .. " created")
			return
	end
	ply:ChatNotify("You have insufficient metal(".. ply.inventory.metal ..") for " .. type .."("..cost..")")
end

concommand.Add( "createweapon", CreateWeapon )  
print( "ButtonHook Script Loaded" ) 
